﻿using INTEX.DataBase;
using INTEX.DataBase.Tools;
using ReflectionStudio.Core;
using ReflectionStudio.Core.Events;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.IO;
using System.Linq;
using System.Windows;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {
        public void YGRVR02LIST(DataSet db)
        {
            int x = 4, y = 1;
            string VKPPOSTYP = "";
            DataTable dtOutput = new DataTable();
            try
            {
                /*
                                     <DataGridTextColumn Binding="{Binding Path=KDKUNDNA}" Header="客户"   Width="Auto"  MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VKKBESTNR}" Header="合同号"  Width="Auto" MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VKPART}" Header="品种"   Width="Auto"  MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VKPFARBE}" Header="色号"   Width="Auto"  MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VKPKDARTNR}" Header="客户纱线"   Width="Auto"  MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VKPKDFARBNR}" Header="客户色号"   Width="Auto"  MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=GPASPPART}" Header="纺批号"   Width="Auto"  MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=GPAFBPART}" Header="缸号"   Width="Auto"  MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VVLIEFSCH,Converter={StaticResource ResourceKey=pnum}}"   Header="发货单"  Width="Auto"  MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VVFRDAT}" Header="发货日期"   Width="Auto"  MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VVTNETKG}" Header="发货数量"  Width="Auto" MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VRPMEEH}" Header="单位"  Width="Auto" MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VKPPREISX}" Header="价格"  Width="Auto" MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=PUM}" Header="UM"  Width="Auto" MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VRPWAWERT}" Header="发货金额"   Width="Auto"  MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VRPGESWERT}" Header="开票金额"   Width="Auto"  MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=GLOAMICUC}" Header="收款金额" Width="Auto" MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=VRKFAELLIG}" Header="货款到期日" Width="Auto" MinWidth="40"/>
                    <DataGridTextColumn Binding="{Binding Path=DUEAMOUNT}" Header="到期货款" Width="Auto" MinWidth="40"/>    
                </DataGrid.Columns>*/
                #region======Title===========
                exAgent.SetCellValue(3, 1, "客户"); dtOutput.Columns.Add("KDKUNDNA", typeof(System.String));
                exAgent.SetCellValue(3, 2, "合同号"); dtOutput.Columns.Add("VKKBESTNR", typeof(System.String));
                exAgent.SetCellValue(3, 3, "品种"); dtOutput.Columns.Add("VKPART", typeof(System.String));
                exAgent.SetCellValue(3, 4, "色号"); dtOutput.Columns.Add("VKPFARBE", typeof(System.Decimal));
                exAgent.SetCellValue(3, 5, "客户纱线"); dtOutput.Columns.Add("VKPKDARTNR", typeof(System.String));
                exAgent.SetCellValue(3, 6, "客户色号"); dtOutput.Columns.Add("VKPKDFARBNR", typeof(System.String));
                exAgent.SetCellValue(3, 7, "纺批号"); dtOutput.Columns.Add("GPASPPART", typeof(System.String));
                exAgent.SetCellValue(3, 8, "缸号"); dtOutput.Columns.Add("GPAFBPART", typeof(System.String));
                exAgent.SetCellValue(3, 9, "发货单"); dtOutput.Columns.Add("VVLIEFSCH", typeof(System.String));
                exAgent.SetCellValue(3, 10, "发货日期"); dtOutput.Columns.Add("VVFRDAT", typeof(System.Decimal));
                exAgent.SetCellValue(3, 11, "价格"); dtOutput.Columns.Add("VRPMEEH", typeof(System.String));
                exAgent.SetCellValue(3, 12, "发货金额"); dtOutput.Columns.Add("VRPWAWERT", typeof(System.String));
                exAgent.SetCellValue(3, 13, "开票金额"); dtOutput.Columns.Add("VRPGESWERT", typeof(System.String));
                exAgent.SetCellValue(3, 14, "收款金额"); dtOutput.Columns.Add("GLOAMICUC", typeof(System.String));
                exAgent.SetCellValue(3, 15, "货款到期日"); dtOutput.Columns.Add("VRKFAELLIG", typeof(System.String));
                exAgent.SetCellValue(3, 16, "到期货款"); dtOutput.Columns.Add("DUEAMOUNT", typeof(System.String)); 
                #endregion

                #region======ConvertData===
                #endregion
                var qGW = from GW in db.Tables["VKPOS"].AsEnumerable()
                          group GW by new
                          {
                              PT = GW["VKPPOSTYP"].ToString(),
                          }
                              into g
                              select new
                              {
                                  KEY = g.Key,
                              };
                foreach (var GW in qGW)
                {
                    VKPPOSTYP = GW.KEY.PT;
                    exAgent.RenameSheet(date);
                    DataRow[] rows = db.Tables["VKPOS"].Select();
                    DataTable dtSoruce = rows.CopyToDataTable();
                    dtOutput.Clear();
                    dtOutput.Merge(dtSoruce, false, MissingSchemaAction.Ignore);
                    foreach (DataRow rx in dtOutput.Rows)
                    {
                    }
                    #region====Excel==========
                    exAgent.DataTableToExcel(dtOutput, x, 1);
                    int count = dtOutput.Rows.Count;
                    MergeSame(x, count);
                    exAgent.SetCellValue(1, 1, 1);
                    exAgent.BatchConvert2Number(4, 9, count + 3, 9);
                    exAgent.BatchConvert2Number(4, 11, count + 3, 14);
                    exAgent.BatchConvert2Number(4, 16, count + 3, 16); 
                    exAgent.SetCellValue(1, 1, " ");
                    #endregion
                    break;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            finally
            {
                EventDispatcher.Instance.RaiseStatus("完成", StatusEventType.StopProgress);
            }
        }

    }
}